<?php
class Admin_Form_ValidateLogin{

	private $_arrError;
	
	private $_arrData;
	
	public function __construct($arrParam = null, $options = null){
		$translate = new Zend_View_Helper_Translate();
		if(!empty($arrParam['email'])){
			if(!empty($arrParam['password'])){
				$db = Zend_Db_Table::getDefaultAdapter();
				$select = $db->select()
							 ->from('users')
							 ->where('email = ?',$arrParam['email']);
				$result = $db->fetchRow($select);
				
				$pass = Zendvn_Encode_Password::encode(trim($arrParam['password']));
				
				if($result['email'] !== trim($arrParam['email'])){
					$this->_arrError['email'] = $translate->translate('This account is not exist.');
				}elseif(!empty($result['active_code']) || $result['active_code'] != NULL ){
					$this->_arrError['email'] = $translate->translate('This account is not active. Please check your email and click link to active account');			
				}elseif($result['status'] == 'inactive'){
					$this->_arrError['email'] = $translate->translate('Sorry! This account is pending. Please contact the administrator to know the reason');
				}elseif($result['password'] !== $pass ){
					$this->_arrError['password'] = $translate->translate('Your password is wrong');
				}
			}else{
				$this->_arrError['password'] = $translate->translate('Please enter your password.');
			}
		}else{
			$this->_arrError['email'] = $translate->translate('Please enter your email.');
		}
		
		$this->_arrData = $arrParam;
	}
	
	public function getData(){
		return $this->_arrData;
	}
	public function isVaild(){
		$flag = false;
		if(count($this->_arrError) > 0){
			$flag = true;
		}
		return $flag;
	}
	public function getMessageErrors(){
		return $this->_arrError;
	}
}
